package com.example.todo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {
    public DBOpenHelper(@Nullable Context context) {
        super(context, "todo.db", null, 4);
    }
    //创建数据库的方法，只有项目第一次运行时，会被调用

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建USER表
        String sql1 = "Create table user(account text primary key,password text,id text,phone text)";
        String sql2 = "Create table todo(id integer primary key autoincrement, title text,context text,createTime text,finishTime text,statu text)";
        db.execSQL(sql1);
        db.execSQL(sql2);
    }


    // 数据库版本在更新时发生改变，会调用此方法
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists user");
        db.execSQL("drop table if exists todo");
        onCreate(db);
    }
}
